<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>

</head>
<body>
    <input type="file">
    <button>上传</button>
    <script>
        $('button').click(function () {
            console.log($('input').val());
            console.log($('input')[0].files[0]);
            //获取要上传的文件对象
            let file = $('input')[0].files[0]

            //在图片上前将图片和上传名称打包成formdata对象
            let formdata = new FormData()
            //将文件对象添加到formdata对象  以此发送给后端
            formdata.append('files',file)

            axios({
                url:'http://192.168.0.30:3301/users/uplode',
                method:'post',
                data:formdata
            })
            .then(res=>{
                console.log(res);
                
            })
        })
    </script>
</body>
</html>